﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;

namespace WP7Client.Helpers
{
    public static class IsolatedStorageHelper
    {
        /// <summary>
        /// Zet data in telefoongeheugen.
        /// </summary>
        /// <param name="field">Veldnaam</param>
        /// <param name="data">Waarde</param>
        public static void SetData(String field, object data)
        {
            try
            {
                IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;

                if (!settings.Contains(field))
                {
                    settings.Add(field, data);
                }
                else
                {
                    settings[field] = data;
                }
                settings.Save();
            }
            catch (Exception ex)
            {
                throw new Exception();
            }
        }

        /// <summary>
        /// Haalt data uit telefoongeheugen
        /// </summary>
        /// <param name="field">Veldnaam</param>
        /// <returns>Waarde</returns>
        public static object GetData(String field)
        {
            try
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(field))
                    return IsolatedStorageSettings.ApplicationSettings[field];
                else
                    return null;
            }
            catch (Exception ex)
            {
                throw new Exception();
            }
        }


        /// <summary>
        /// Verwijderd data uit het telefoongeheugen.
        /// </summary>
        /// <param name="field">Veldnaam</param>
        public static void DeleteData(String field)
        {
            try
            {
                if (IsolatedStorageSettings.ApplicationSettings.Contains(field))
                    IsolatedStorageSettings.ApplicationSettings.Remove(field);
                
            }
            catch (Exception ex)
            {
                throw new Exception();
            }
        }
    }
}
